package com.thor.palmmall.dao.banlancebill;

import org.springframework.core.convert.converter.Converter;

import com.thor.palmmall.rest.balancebill.BanlanceBill;
import com.thor.palmmall.rest.balancebill.BanlanceBillDetail;

public class PBanlanceBillConverter  implements Converter<BanlanceBill, PBanlanceBill>{
  private static PBanlanceBillConverter instance;
  public static PBanlanceBillConverter getInstance() {
    if (instance == null) {
      instance = new PBanlanceBillConverter();
    }
    return instance;
  }
  
  @Override
  public PBanlanceBill convert(BanlanceBill source) {
    if (source == null) {
      return null;
    }
    PBanlanceBill target = new PBanlanceBill();
    target.inject(source);
    target.setBillNo(source.getBillNo());
    target.setStore(source.getStore());
    target.setTenant(source.getTenant());
    target.setContract(source.getContract());
    target.setPayTotal(source.getPayTotal());
    target.setPayedTotal(source.getPayedTotal());
    target.setUnpayedTotal(source.getUnpayedTotal());
    target.setBillState(source.getBillState());
    target.setAttachmentId(source.getAttachmentId());
    target.setBillSettle(source.getBillSettle());
    target.setLegalName(source.getLegalName());
    target.setTaxCode(source.getTaxCode());
    target.setLegalPersion(source.getLegalPersion());
    target.setAddress(source.getAddress());
    target.setPhone(source.getPhone());
    target.setContractType(source.getContractType());
    if(source.getDetails() != null && source.getDetails().size() > 0){
      for (BanlanceBillDetail detail : source.getDetails()) {
        PBanlanceBillDetail pDetail = new PBanlanceBillDetailConvert().convert(detail);
        pDetail.setBill(target);
        target.getDetails().add(pDetail);
      }
    }
    return target;
  }

}
